using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "创建ScriptableObject/BuffData/Base")]
public abstract class BuffData : ScriptableObject
{
    /// <summary>
    /// Buff名称
    /// </summary>
    public string BuffName;

    /// <summary>
    /// BuffId
    /// </summary>
    public int BuffID;

    /// <summary>
    /// 特效预制体
    /// </summary>
    public GameObject Effect;

    /// <summary>
    /// Buff类型
    /// </summary>
    public BuffType BuffType;

    /// <summary>
    /// 是否能够合并
    /// </summary>
    public bool IsCanMerge;

    /// <summary>
    /// 延迟时间
    /// </summary>
    public float Delay;

    /// <summary>
    /// 持续时间
    /// </summary>
    public float Duration;

    /// <summary>
    /// Buff携带的Tag
    /// </summary>
    public BuffTag Tags;

    /// <summary>
    /// 会被哪些 Tag 免疫
    /// </summary>
    public BuffTag Immune_Tags;

    /// <summary>
    /// 在Inspector中的Reset时调用
    /// </summary>
    private void Reset()
    {
        // 根据具体类型设置默认移动类型
        if (this is KnockbackData)
            BuffType = BuffType.Knockback;
        else if (this is SlowData)
            BuffType = BuffType.Slow;
        else if (this is FreezeData)
            BuffType = BuffType.Freeze;
        else if (this is BurnData)
            BuffType = BuffType.Burn;
        else if (this is RegenerationData)
            BuffType = BuffType.Regeneration;
        else if (this is PhysicalShieldData)
            BuffType = BuffType.PhysicalShield;
        else if (this is AttrBuffData)
            BuffType = BuffType.AttrData;
        else if (this is DashData)
            BuffType = BuffType.Dash;
        else if (this is GrappleData)
            BuffType = BuffType.Grapple;
        else if (this is BlowAwayData)
            BuffType = BuffType.BlowAway;
        else if (this is SwapData)
            BuffType = BuffType.Swap;
        else if (this is CurseData)
            BuffType = BuffType.Curse;
        else if (this is SummonData)
            BuffType = BuffType.Summon;
        else if (this is ThornsData)
            BuffType = BuffType.Thorns;
        else if (this is WeaknessData)
            BuffType = BuffType.Weakness;
        else if (this is ArmorShredData)
            BuffType = BuffType.ArmorShred;
        else if (this is VulnerabilityData)
            BuffType = BuffType.Vulnerability;
        else if (this is SluggishData)
            BuffType = BuffType.Sluggish;
        else if (this is BleedData)
            BuffType = BuffType.Bleed;
        else if (this is CorrosionData)
            BuffType = BuffType.Corrosion;
        else if (this is SnareData)
            BuffType = BuffType.Snare;
        else if (this is SilenceData)
            BuffType = BuffType.Silence;
        else if (this is DisarmData)
            BuffType = BuffType.Disarm;
        else if (this is BlindData)
            BuffType = BuffType.Blind;
        else if (this is TauntData)
            BuffType = BuffType.Taunt;
        else if (this is CharmData)
            BuffType = BuffType.Charm;
        else if (this is FearData)
            BuffType = BuffType.Fear;
        else if (this is ConfuseData)
            BuffType = BuffType.Confuse;
        else if (this is SleepData)
            BuffType = BuffType.Sleep;
        else if (this is PetrifyData)
            BuffType = BuffType.Petrify;
        else if (this is ShockData)
            BuffType = BuffType.Shock;
        else if (this is ChillData)
            BuffType = BuffType.Chill;
        else if (this is CurseData)
            BuffType = BuffType.Curse;
        else if (this is SummonData)
            BuffType = BuffType.Summon;
        else if (this is ThornsData)
            BuffType = BuffType.Thorns;
        else if (this is WeaknessData)
            BuffType = BuffType.Weakness;
        else if (this is ArmorShredData)
            BuffType = BuffType.ArmorShred;
        else if (this is VulnerabilityData)
            BuffType = BuffType.Vulnerability;
        else if (this is SluggishData)
            BuffType = BuffType.Sluggish;
        else if (this is InvincibleData)
            BuffType = BuffType.Invincible;
        else if (this is SuperArmorData)
            BuffType = BuffType.SuperArmor;
        else if (this is SpellShieldData)
            BuffType = BuffType.SpellShield;
        else if (this is CleanseData)
            BuffType = BuffType.Cleanse;
        else if (this is ReviveData)
            BuffType = BuffType.Revive;
        else if (this is StealthData)
            BuffType = BuffType.Stealth;
        else if (this is KnockbackData)
            BuffType = BuffType.Knockback;
        else if (this is PullData)
            BuffType = BuffType.Pull;
        else if (this is KnockUpData)
            BuffType = BuffType.KnockUp;
        else if (this is BlinkData)
            BuffType = BuffType.Blink;
        else if (this is DashData)
            BuffType = BuffType.Dash;
        else if (this is GrappleData)
            BuffType = BuffType.Grapple;
        else if (this is BlowAwayData)
            BuffType = BuffType.BlowAway;
        else if (this is SwapData)
            BuffType = BuffType.Swap;
        else if (this is RegenerationData)
            BuffType = BuffType.Regeneration;
        else if (this is LifeLeechData)
            BuffType = BuffType.LifeLeech;
        else if (this is ManaRegenData)
            BuffType = BuffType.ManaRegen;
    }
}

[System.Flags]
public enum BuffTag
{
    //注意：开启unity 会自动添加Nothing,Eventhing等枚举，它们的值分别是0和-1

    /// <summary>
    /// 无
    /// </summary>
    None = 2,

    /// <summary>
    /// 减速
    /// </summary>
    Slow = 4,

    /// <summary>
    /// 击退
    /// </summary>
    Knockback = 8,

    /// <summary>
    /// 控制效果
    /// </summary>
    Control = 16,

    /// <summary>
    /// 伤害效果
    /// </summary>
    Damage = 32,

    /// <summary>
    /// 治疗效果
    /// </summary>
    Heal = 64,

    /// <summary>
    /// 防御效果
    /// </summary>
    Defense = 128,

    /// <summary>
    /// 移动效果
    /// </summary>
    Movement = 256,

    /// <summary>
    /// 属性效果
    /// </summary>
    Attribute = 512,

    /// <summary>
    /// 净化效果
    /// </summary>
    Cleanse = 1024,

    /// <summary>
    /// 免疫效果
    /// </summary>
    Immune = 2048,

    /// <summary>
    /// 物理效果
    /// </summary>
    Physical = 4096,

    /// <summary>
    /// 魔法效果
    /// </summary>
    Magic = 8192,

    /// <summary>
    /// 火焰效果
    /// </summary>
    Fire = 16384,

    /// <summary>
    /// 冰霜效果
    /// </summary>
    Ice = 32768,

    /// <summary>
    /// 毒素效果
    /// </summary>
    Poison = 65536,

    /// <summary>
    /// 闪电效果
    /// </summary>
    Lightning = 131072,

    /// <summary>
    /// 真实伤害效果
    /// </summary>
    True = 262144,

    /// <summary>
    /// 负面效果
    /// </summary>
    Debuff = 524288,

    /// <summary>
    /// 隐身效果
    /// </summary>
    Stealth = 1048576,

    /// <summary>
    /// 召唤效果
    /// </summary>
    Summon = 2097152,
}

public static class BuffTagUtil
{
    /// <summary>
    /// 检查当前BuffTag是否包含所有指定标签（mask中的所有位都必须设置）
    /// </summary>
    public static bool BuffTagHasAll(this BuffTag self, BuffTag mask) => (self & mask) == mask;
    
    /// <summary>
    /// 检查当前BuffTag是否包含任意指定标签（mask中任意一位设置即可）
    /// </summary>
    public static bool BuffTagHasAny(this BuffTag self, BuffTag mask) => (self & mask) != 0;
}